package com.example.tys.baseapplication.NetModel.executor.rxandroid;

import android.util.Log;
import android.widget.Toast;

import com.example.tys.baseapplication.MyApp;

import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;

/**
 * Created by tys on 2017/10/2.
 */

public class BaseObserver<T> implements io.reactivex.Observer<T> {

    private static final String TAG = "BaseObserver";

    @Override
    public void onSubscribe(@NonNull Disposable d) {
    }

    @Override
    public void onNext(@NonNull T response) {
        success(response);
    }

    @Override
    public void onError(@NonNull Throwable e) {
        error(e);
    }

    @Override
    public void onComplete() {

    }

    protected void success(T response) {
    }

    protected void error(Throwable e) {
        //UI 线程异常统一处理
        Log.e(TAG, e.toString());
        Toast.makeText(MyApp.getInstance(),e.getMessage(), Toast.LENGTH_SHORT).show();
    }


}
